/*
 * @Author: Wangjun
 * @Date: 2023-08-14 10:40:47
 * @LastEditTime: 2023-10-26 16:44:09
 * @LastEditors: Wangjun
 * @Description:
 * @FilePath: \nodex\nodecmp\op_hmh.go
 * hnxr
 */
package nodecmp

import (
	"gitee.com/hnxr_1/nodex"
)

//0:> 1>= 2 < 3:<= 4== 5 !=
//M

func init() {
	nodex.Reister(new(Hmh))
}

type Hmh struct {
	nodex.Node
	X nodex.Double  `remark:"输入"`
	H nodex.Double  `remark:"上限"`
	D nodex.Double  `remark:"迟滞宽度,1"` //迟滞宽度
	Y nodex.Boolean `remark:"输出Y,,out"`
}

func (m *Hmh) GetModelID() int {
	return nodex.ModCmp
}

func (m *Hmh) GetName() string {
	return "HMH"
}

/**
 * @description: 节点信息
 * @return {*}
 */
func (m *Hmh) RegData() []byte {
	return nodex.MakeRegData(m, "高限迟滞", m.GetName(), "")
}

// //0:> 1>= 2 < 3:<= 4== 5 !=
func (m *Hmh) Calc() (err error) {
	if m.EnQ {
		if *m.X.Bad || *m.H.Bad || *m.D.Bad {
			m.Bad = true
			return //不计算
		}
	}

	m.Bad = false
	if m.X.Value >= m.H.Value {
		m.Y.Value = true
		return
	}
	if m.X.Value < (m.H.Value - m.D.Value) {
		m.Y.Value = false
		return
	}

	return
}
